# -*- coding: utf-8 -*-
"""
Created by #zqy_TheBest on 2024/6/8
Description: 
"""

# Your code goes here
import json
import re
import time
from .getPublicData import *

import json

def getPriceSortData():
    cars = list(getAllCars())  # 假设 getAllCars() 函数返回一个包含汽车信息的列表
    priceSortList = {"0-5w": 0, "5-18w": 0, "10-20w": 0, "20-30w": 0, "30w以上": 0}  # 字典初始化

    for i in cars:
        s = [json.loads(i.price)[0]][0]

        if s <= 5:
            priceSortList['0-5w'] += 1
        elif 5 < s and s < 10:  # 使用 'and' 而不是 '.' 来连接条件
            priceSortList['5-18w'] += 1
        elif 10 <= s and s < 20:  # 修正范围和条件
            priceSortList['10-20w'] += 1
        elif 20 <= s and s < 30:  # 修正范围和条件
            priceSortList['20-30w'] += 1
        else:
            priceSortList['30w以上'] += 1

    # print(priceSortList)
    realData = []

    for k, v in priceSortList.items():
        realData.append({
            'name': k,
            'value': v
        })

    # print(realData)
    return realData